package com.example.bluetoothapplication.bluetooth;

import android.os.Handler;
import android.os.Message;

import com.coszero.utilslibrary.utils.LogX;

public class BluetoothResponseHandler extends Handler {
    private final String TAG = "BluetoothResponseHandler";

    public BluetoothResponseHandler() {
    }


    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case BluetoothConstant.MESSAGE_STATE_CHANGE:
                LogX.i("MESSAGE_STATE_CHANGE: " + msg.arg1);
                switch (msg.arg1) {
                    case DeviceConnector.STATE_CONNECTED:
                        LogX.i(TAG, "蓝牙已连接");
                        break;
                    case DeviceConnector.STATE_CONNECTING:
                        LogX.i(TAG, "蓝牙连接中");
                        break;
                    case DeviceConnector.STATE_NONE:
                        LogX.i(TAG, "蓝牙未连接");
                        break;
                }
                break;

            case BluetoothConstant.MESSAGE_READ:
                final String readMessage = (String) msg.obj;
                if (readMessage != null) {
                    LogX.i("###读取数据：" + readMessage);
//                        activity.appendLog(readMessage, false, false, activity.needClean);
                }
                break;

            case BluetoothConstant.MESSAGE_DEVICE_NAME:
//                    activity.setDeviceName((String) msg.obj);
                break;

            case BluetoothConstant.MESSAGE_WRITE:
                // stub
                break;

            case BluetoothConstant.MESSAGE_TOAST:
                // stub
                break;
        }
    }
}
